# Aqua makefile 

VERSION = 3.2

# Insert location of top directory here. 
# Note: make does not understand ~ . Use the full path instead, or maybe $(HOME)
# should be http browsable in case of server setup
#MYROOT   = /Users/jd/progs

#MYROOT   = $(WS)
#AQUAROOT = $(MYROOT)/aquad

# No changes for the following variables are needed unless you want to update
# the aqua web server or homepage;-)
AQUAHOME =  /Users/jd/external_html/aqua
EXPORT   = $(AQUAROOT)/export/aqua$(VERSION)
LIB      = $(AQUAROOT)/sub/lib
BIN      = $(AQUAROOT)/bin
EXMPLS   = $(AQUAROOT)/exmpls
SCRIPTS  = $(AQUAROOT)/scripts

# Tested on Linux RedHat 6.2 and SunOS 5.7 and Mac OS X.5.2
# No compiler warnings were generated using these options.
CC      = g++                        
#CFLAGS	= -O -I$(LIB) -Wall -g       
CFLAGS	= -O -I$(LIB) -w -g       

# Tested on SGI Irix 6.4
# No compiler warnings were generated using these options. If the -fullwarn
# option is added there will be trivial warnings.
# You might not need the -n32 -mips3 options
FORTRAN = gfortran                                       
FFLAGS	=           


FFLAGS	= -O2
# LDFLAGS = -lI77
LDFLAGS =
OBJECTS	= AquaFuncts.o AquaStrucset.o AquaFiles.o $(LIB)/MenuFuncts.o $(LIB)/Functs.o
R_OBJECTS = AquaFuncts_cv.o AquaFuncts_io.o 
RNG_OBJECTS = AquaRange.o Range.o 

# The directory where the star library exists. No need to change these as you
# will not need the star reading capabilities (yet).
STARLIBDIR = $(MYROOT)/starlib
# The flags to give the compiler:
STARFLAGS = -DNO_POSBITS_DATAVALUENODE -DIS_LINUX -DIS_GCC \
            -L$(STARLIBDIR) -I$(STARLIBDIR)            
STARLIBS =  -L$(STARLIBDIR) $(STARLIBDIR)/template.o -lstar -lfl
           
# Note: add cv_subs.o to R_OBJECTS and -DCVALL to CFLAGS to use Fortran cvall 

IO_FILES = AquaFuncts_io.c AquaFuncts_biosym.c AquaFuncts_xplor.c AquaFuncts_diana.c \
           AquaFuncts_pdb.c AquaFuncts_pdbmr.c AquaFuncts_nmrstar.c 

Q_HEADERS = $(LIB)/Compiler.h $(LIB)/General.h AquaMacros.h AquaTypes.h 
G_HEADERS = $(LIB)/Compiler.h $(LIB)/General.h
.SUFFIXES: .h



# MAIN TARGET: Complete rebuild. Target exth should be done first!
#
# Note: the 'genh' script generates a .h file from a .c file using 'exth'.
# After unpacking the Aqua distribution all .h files are correct, so:
# IF YOU DON'T HAVE A FORTRAN COMPILER you may skip the compilation of exth.f
# (but if you modify the code you will have to remove the .h targets in this
# makefile: remove the parts between lines
#    "### define .h target"
# and 
#    "### end define .h target"
# and update the .h files by hand if necessary).
#
# To make sure that 'make' does not invoke 'exth', first issue:
#    touch *.h ../lib/*.h
# and then:
#    touch AquaFuncts_io.h
# and remove 'exth' from the list immediately below this line.

all:	$(BIN)/getproj $(BIN)/AquaWhat $(BIN)/AquaHow $(BIN)/AquaPseudo \
	$(BIN)/AquaDist $(BIN)/AquaCalc \
	$(BIN)/AquaAssign $(BIN)/AquaCompl $(BIN)/AquaRedun 


# Shorthand entries

what:	$(BIN)/AquaWhat

how:	$(BIN)/AquaHow

pseudo:	$(BIN)/AquaPseudo

dist:	$(BIN)/AquaDist

calc:	$(BIN)/AquaCalc

assign:    $(BIN)/AquaAssign

compl:    $(BIN)/AquaCompl

redun:    $(BIN)/AquaRedun

testnew:    $(BIN)/testnew

getproj:    $(BIN)/getproj

qext:	$(BIN)/Qext

plot:	$(BIN)/AquaPlot

strip:
	strip $(BIN)/*

clean:
	-\rm *.o
	-\rm $(LIB)/*.o
	@echo "Next remove command might throw an error that can be ignored" 
	-\rm $(BIN)/*

test:
	@echo "# Expect differences (if any) in the sign of values close to zero"
	$(SCRIPTS)/tstinst $(AQUAROOT) $(EXMPLS)
        

export:
	rm -rf $(EXPORT)
	make clean
	echo "setenv aquaroot $(AQUAROOT); $(AQUAROOT)/tools/prepexp" | csh
	mkdir $(EXPORT)
	echo "setenv aquaroot $(AQUAROOT); cd $(AQUAROOT); $(AQUAROOT)/tools/export $(EXPORT) " | csh
	echo "setenv aquaroot $(AQUAROOT); $(AQUAROOT)/tools/postexp $(EXPORT)" | csh
	cd $(EXPORT)/..; tar -cf aqua$(VERSION).tar aqua$(VERSION); compress aqua$(VERSION).tar; \mv -f $(EXPORT).tar.Z $(AQUAROOT)/aqua_home
	rm -rf $(EXPORT)
	# untested next line.
	find . -name ".export" -exec rm {} \;
	

server:
	@echo '#making a server at servers location'
	@echo '#Supplied the locations in scripts/server.pl??'
	$(AQUAROOT)/scripts/server.pl $(AQUAROOT)

home:
	@echo '#making the aqua home pages at home location'
	-\rm -r $(AQUAHOME)
	\cp -r $(AQUAROOT)/aqua_home $(AQUAHOME)

star_test: $(BIN)/StarTest
	

##### Header files
####### define .h target
####
####.c.h:
####	$(AQUAROOT)/src/genh $(*F) $(AQUAROOT)/src
####
####AquaFuncts_io.h:    AquaFuncts_io.c\
####		    AquaFuncts_biosym.h AquaFuncts_xplor.h AquaFuncts_diana.h\
####		    AquaFuncts_pdb.h AquaFuncts_pdbmr.h AquaFuncts_nmrstar.h
####	$(AQUAROOT)/src/genh AquaFuncts_io $(AQUAROOT)/src
####	@echo '#include "AquaFuncts_biosym.h"'  >> AquaFuncts_io.h
####	@echo '#include "AquaFuncts_xplor.h"'   >> AquaFuncts_io.h
####	@echo '#include "AquaFuncts_diana.h"'   >> AquaFuncts_io.h
####	@echo '#include "AquaFuncts_pdb.h"'     >> AquaFuncts_io.h
####	@echo '#include "AquaFuncts_pdbmr.h"'   >> AquaFuncts_io.h
####	@echo '#include "AquaFuncts_nmrstar.h"' >> AquaFuncts_io.h
####
####$(LIB)/Functs.h:	$(LIB)/Functs.c
####	$(AQUAROOT)/src/genh $(LIB)/Functs $(AQUAROOT)/src
####
####$(LIB)/MenuFuncts.h:	$(LIB)/MenuFuncts.c
####	$(AQUAROOT)/src/genh $(LIB)/MenuFuncts $(AQUAROOT)/src
####
####Range.h:
####	touch Range.h
####
####nrutil.h:
####	touch nrutil.h
####
####### end define .h target


# Executable files

$(BIN)/AquaWhat:    AquaWhat.o $(OBJECTS) $(R_OBJECTS) $(RNG_OBJECTS)
	$(CC) -o $(BIN)/AquaWhat AquaWhat.o $(OBJECTS) $(R_OBJECTS) $(RNG_OBJECTS) $(LDFLAGS)

$(BIN)/AquaHow:	    AquaHow.o $(OBJECTS) $(R_OBJECTS) AquaFuncts_dr.o $(RNG_OBJECTS)
	$(CC) -o $(BIN)/AquaHow AquaHow.o $(OBJECTS) $(R_OBJECTS) AquaFuncts_dr.o $(RNG_OBJECTS) $(LDFLAGS)

$(BIN)/AquaPseudo:  AquaPseudo.o $(OBJECTS) $(R_OBJECTS) 
	$(CC) -o $(BIN)/AquaPseudo AquaPseudo.o $(OBJECTS) $(R_OBJECTS) $(LDFLAGS)

$(BIN)/AquaDist:    AquaDist.o $(OBJECTS) 
	$(CC) -o $(BIN)/AquaDist AquaDist.o $(OBJECTS) $(LDFLAGS) -lm

$(BIN)/AquaCalc:    AquaCalc.o $(OBJECTS) $(RNG_OBJECTS)
	$(CC) -o $(BIN)/AquaCalc AquaCalc.o $(OBJECTS) $(RNG_OBJECTS) $(LDFLAGS) -lm

$(BIN)/AquaAssign:  AquaAssign.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS)
	$(CC) -o $(BIN)/AquaAssign AquaAssign.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS) $(LDFLAGS)

$(BIN)/AquaCompl:  AquaCompl.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS) 
	$(CC) -o $(BIN)/AquaCompl AquaCompl.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS) $(LDFLAGS) -lm  

$(BIN)/AquaRedun:  AquaRedun.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS) 
	$(CC) -o $(BIN)/AquaRedun AquaRedun.o AquaCommon.o $(OBJECTS) $(R_OBJECTS) nrutil.o AquaFuncts_dr.o $(RNG_OBJECTS) $(LDFLAGS)

$(BIN)/testnew:	    testnew.o $(OBJECTS)
	$(CC) -o $(BIN)/testnew testnew.o $(OBJECTS) $(LDFLAGS)

$(BIN)/getproj:    getproj.c 
	$(CC) -o $(BIN)/getproj -O getproj.c

$(BIN)/AquaPlot:    AquaPlot.o $(LIB)/MenuFuncts.o $(LIB)/Functs.o
	$(CC) -o $(BIN)/AquaPlot AquaPlot.o $(LIB)/MenuFuncts.o $(LIB)/Functs.o $(LDFLAGS)

$(BIN)/Qext:	   Qext.o $(LIB)/MenuFuncts.o $(LIB)/Functs.o
	$(CC) -o $(BIN)/Qext Qext.o $(LIB)/MenuFuncts.o $(LIB)/Functs.o $(LDFLAGS)

$(BIN)/StarTest:	StarTest.o
	$(CC) -o $(BIN)/StarTest StarTest.o $(LDFLAGS) $(STARFLAGS) $(STARLIBS)

exth:		exth.f
	$(FORTRAN) -o exth -O2 exth.f $(FFLAGS) 
	strip exth


# Object files

AquaWhat.o:	AquaWhat.c AquaWhat.h AquaRange.h AquaFuncts.h AquaFuncts_io.h\
		AquaStrucset.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaWhat.c $(CFLAGS)

AquaHow.o:	AquaHow.c AquaHow.h AquaFuncts.h AquaFuncts_io.h AquaFuncts_dr.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaHow.c $(CFLAGS)

AquaPseudo.o:	AquaPseudo.c AquaPseudo.h AquaFuncts.h AquaFuncts_io.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaPseudo.c $(CFLAGS)

AquaDist.o:	AquaDist.c AquaDist.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaDist.c $(CFLAGS)

# AquaCalc: remove -DCLEAN0 if not on Unix system; then run 'clean0' on output 
# externally instead of from within AquaCalc via 'system' call

AquaCalc.o:	AquaCalc.c AquaCalc.h AquaRange.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaCalc.c $(CFLAGS) -DCLEAN0

AquaAssign.o:	AquaAssign.c AquaAssign.h AquaCommon.h nrutil.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h AquaFuncts_dr.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS) AquaTypes_Assign.h
	$(CC) -c AquaAssign.c $(CFLAGS)

AquaCompl.o:	AquaCompl.c AquaCompl.h AquaCommon.h nrutil.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h AquaFuncts_dr.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaCompl.c $(CFLAGS)

AquaRedun.o:	AquaRedun.c AquaRedun.h AquaCommon.h nrutil.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h AquaFuncts_dr.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS) AquaTypes_Assign.h
	$(CC) -c AquaRedun.c $(CFLAGS)

AquaCommon.o:	AquaCommon.c AquaCommon.h nrutil.h \
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS) AquaTypes_Assign.h
	$(CC) -c AquaCommon.c $(CFLAGS)

nrutil.o:	nrutil.c nrutil.h
	$(CC) -c nrutil.c -DANSI

AquaFuncts.o:	AquaFuncts.c AquaFuncts.h AquaFuncts_cv.h AquaFuncts_io.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS) AquaData.h
	$(CC) -c AquaFuncts.c $(CFLAGS)

AquaFuncts_cv.o: AquaFuncts_cv.c AquaFuncts_cv.h cv_subs.h\
		AquaFuncts.h AquaFuncts_io.h\
		$(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaFuncts_cv.c $(CFLAGS)

AquaFuncts_io.o: $(IO_FILES) AquaFuncts_io.h\
		AquaFuncts.h AquaFuncts_cv.h AquaStrucset.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaFuncts_io.c $(CFLAGS)

AquaFuncts_dr.o: AquaFuncts_dr.c AquaFuncts_dr.h AquaRange.h AquaFuncts.h AquaFuncts_io.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaFuncts_dr.c $(CFLAGS)

AquaStrucset.o:	AquaStrucset.c AquaStrucset.h AquaFuncts.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaStrucset.c $(CFLAGS)

AquaFiles.o:	AquaFiles.c AquaFiles.h AquaFuncts.h AquaStrucset.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS) AquaData.h
	$(CC) -c AquaFiles.c $(CFLAGS)

AquaRange.o:	AquaRange.c AquaRange.h Range.h AquaFuncts.h AquaStrucset.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c AquaRange.c $(CFLAGS)

Range.o:	Range.c Range.h
	$(CC) -c Range.c $(CFLAGS)

testnew.o:	testnew.c testnew.h AquaFuncts.h\
		AquaStrucset.h AquaFiles.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(Q_HEADERS)
	$(CC) -c testnew.c $(CFLAGS)

$(LIB)/Functs.o:	$(LIB)/Functs.c $(LIB)/Functs.h $(G_HEADERS)
	cd $(LIB); $(CC) -c Functs.c $(CFLAGS)

$(LIB)/MenuFuncts.o:	$(LIB)/MenuFuncts.c $(LIB)/MenuTypes.h $(LIB)/MenuFuncts.h\
			$(LIB)/Functs.h $(G_HEADERS)
	cd $(LIB); $(CC) -c MenuFuncts.c $(CFLAGS)

cv_subs.o:	cv_subs.f
	f77 -c cv_subs.f $(FFLAGS)

Qext.o:		Qext.c Qext.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(G_HEADERS)
	$(CC) -c Qext.c $(CFLAGS)

AquaPlot.o:	AquaPlot.c AquaPlot.h\
		$(LIB)/MenuFuncts.h $(LIB)/Functs.h $(G_HEADERS)
	$(CC) -c AquaPlot.c $(CFLAGS)

StarTest.o:	StarTest.cc
	$(CC) -c StarTest.cc $(CFLAGS) $(STARFLAGS)

